<%layout("/common/_layout.html"){ %>
<style>
	.table-title{
		width: 150px;
	}

</style>
<script type="text/javascript">
var keywordsObj = {};
var submit_btn = function(businessType){
    if($("#endTime").val()!="" && $("#endTime").val() < $("#startTime").val()){
    	alert("结束时间不能小于开始时间");
    	return false;
    }
    if($("#startTime").val())
        keywordsObj.start_time = $("#startTime").val();
    if($("#endTime").val())
        keywordsObj.end_time = $("#endTime").val();
	if($("#name").val())
		keywordsObj.name = $("#name").val();
    console.log
    var keywords = "";
    if(!$.isEmptyObject(keywordsObj)){
      keywords = JSON.stringify(keywordsObj);
    }
    $("#keywords").val(keywords);
	if(businessType == "search"){
		$("#list-form").submit();
	}else if(businessType == "export"){
		window.location.href = "${base}/recommend/exportAll?keywords="+keywords;
	}
}
document.onkeydown = function(event){
	if(event.keyCode==13){
		submit_btn('search');
	}
}
var deletePromo = function(url){
	var $idsCheckedCheck = $("[name='ids']:checked");
	var $deleteButton = $("#deleteButton");// 删除按钮
	var ids = $idsCheckedCheck.serialize();
	if(window.confirm('你确定要删除选中数据吗？')){
		$.ajax({
			url : url,
			data : ids,
			dataType : "json",
			async : false,
			beforeSend : function(data) {
				$deleteButton.prop("disabled", true)
			},
			success : function(data) {
				$deleteButton.prop("disabled", false)
				if(data.message=="success"){
					alert("删除成功");
					window.location.href="${base}/activity/list?pageNumber=1&pageSize=10";
				}else if(data.message=="failed"){
					alert("删除失败");
				}
			}

		});
	}
}
$(function(){

})
</script>

<%#ajax userTable:{%>
<div class="am-cf am-padding">
	<div class="am-fl am-cf">
		<strong class="am-text-primary am-text-lg">业务配置</strong> /<small>活动大类列表</small>
	</div>
</div>


<div class="am-g">
	<%include("activity_list_query.tpl"){}%>
	<div class="am-u-sm-12 am-u-md-12"
		 style="padding: 0 1.6rem 1.6rem 1rem; margin: 0;">
		<div class="am-btn-toolbar" style="padding-left: .5rem;">
			<div class="am-btn-group am-btn-group-xs">
				<div class="am-btn-group am-btn-group-xs am-form-file">
					<%if(so.hasPermission("ACTIVITY_ADD")) {%>
					<button type="button" id="bt_add" class="am-btn"
							onclick="location.href='${base}/activity/add'">
						<span class="am-icon-plus"> 新增</span>
					</button>
					<%}%>
					<%if(so.hasPermission("ACTIVITY_DELETE")) {%>
					<button type="button" id="deleteButton" disabled="disabled" class="am-btn am-btn-default" onclick="deletePromo('${base}/activity/deletePromo')"><span class="am-icon-trash-o"></span> 删除</button>
					<%}%>
				</div>
			</div>
		</div>
	</div>
</div>


	<div class="am-g">
		<div class="am-u-sm-12">
			<%if(pager.totalRow > 0){%>
			<div class="am-scrollable-horizontal">
				<table class="am-table am-table-striped am-table-hover table-main" style="TABLE-LAYOUT: fixed">
					<thead>
						<tr class="am-text-nowrap">
							<th class="table-check"><input type="checkbox" id="allCheck"></th>
							<th class="table-title">名称</th>
							<th class="table-title" style="width: 80px;">类型代码</th>
							<th class="table-title" style="width: 80px;">类型名称</th>
							<th class="table-title">活动说明</th>
							<th class="table-title">排序字段</th>
							<th class="table-title">创建时间</th>
							<th class="table-title">上一次修改时间</th>
							<th class="table-title">操作</th>
						</tr>
					</thead>
					<tbody>
						<%for(item in pager.list!){%>
						<tr>
							<td><input type="checkbox" <%{%>name="ids" value="${item.id}"<%}%> /></td>
							<td style="word-wrap:break-word;">${item.name}</td>
							<td style="word-wrap:break-word;">${item.type}</td>
							<td style="word-wrap:break-word;">${item.typeName}</td>
							<td style="word-wrap:break-word;">${item.remark}</td>
							<td style="word-wrap:break-word;">${item.sort}</td>
							<td style="word-wrap:break-word;">${item.created_time, dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
							<td style="word-wrap:break-word;">${item.last_updated_time, dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
							<td>
								<div class="am-btn-toolbar">
									<div class="am-btn-group am-btn-group-xs">
										<%if(so.hasPermission("ACTIVITY_EDIT")) {%>
										<div style="float: left">
											<button type="button"
													class="am-btn am-btn-default am-btn-xs am-text-secondary"
													onclick="location.href='${base}/activity/edit?id=${item.id}'">
												<span class="am-icon-pencil-square-o"></span>编辑
											</button>&nbsp;&nbsp;
										</div>
										<%}%>
									</div>
								</div>
							</td>
						</tr>
						<%}%>
					</tbody>
				</table>
			</div>
			<%}%>
			<div class="am-cf">
				<!-- 分页 -->
				<%if (pager.list.~size > 0){%>
				<div class="am-fr"><% include("/admin/common_pager.tpl"){}%></div>
				<%}else{%>
				<div class="am-kai" style="padding-bottom: 150px;">
					<h3>没有找到任何记录!</h3>
				</div>
				<%}%>
			</div>

		</div>
	</div>
	<div class="am-modal am-modal-no-btn" tabindex="-1" id="modal">
		<div class="am-modal-dialog">
			<div class="am-modal-hd">
				<i class="am-icon-refresh am-icon-spin"></i> <a
					href="javascript: void(0)" class="am-close am-close-spin"
					data-am-modal-close>&times;</a>
			</div>
			<div class="am-modal-bd">正在处理，请稍等...</div>
		</div>
	</div>
	<%}%> <%}%>